import java.util.ArrayList;
import java.util.List;

//路由汇总

public class CIDRSummarization {

    public static String summarize(String... ips) {
        int[][] ipAdresses = new int[ips.length][];
        for (int i = 0; i < ips.length; i++) {
            ipAdresses[i] = toIntArray(ips[i]);
        }

        int bitCount = 0;
        boolean bitsDiffer = false;
        for (int b = 0; b < 32; b++) {
            boolean bit = bitSet(ipAdresses[0], b);
            for (int[] ipAddress : ipAdresses) {
                if (bitSet(ipAddress, b) != bit) {
                    bitsDiffer = true;
                    break;
                }
            }
            if (bitsDiffer) {
                break;
            }
            bitCount++;
        }

        int[] resultIp = ipAdresses[0];
        for (int i = bitCount; i < 32; i++) {
            resultIp = clearBit(resultIp, i);
        }

        return toString(resultIp) + "/" + bitCount;
    }

    private static int[] toIntArray(String ip) {
        String[] parts = ip.split("\\.");
        return new int[]{Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3])};
    }

    private static String toString(int[] ip) {
        return ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];
    }

    private static boolean bitSet(int[] ip, int bit) {
        return (ip[bit / 8] & (1 << (7 - bit % 8))) != 0;
    }

    private static int[] clearBit(int[] ip, int bit) {
        ip[bit / 8] &= ~(1 << (7 - bit % 8));
        return ip;
    }

    public static void main(String[] args) {
        System.out.println(summarize("172.112.0.0", "172.116.0.0", "172.120.0.0"));
    }
}